]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
messageTray: Ensure that a notification is removed from Source correctly
authorJulian Sparber <julian@sparber.net>
Thu, 7 Mar 2024 10:00:35 +0000 (11:00 +0100)
committerMarge Bot <marge-bot@gnome.org>
Wed, 13 Mar 2024 11:21:35 +0000 (11:21 +0000)
We need to make sure that we always emit the `notification-removed`
signal on the source object when a notification is removed or
destroyed.

Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/7463
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3229>

js/ui/messageTray.js

index 10ae5b2fbb3321b8e5bc3721bda3f1bbfe28cb76..1a9ac66555e4575125a4916ddc87684808e919ec 100644 (file)
@@ -541,13 +541,13 @@ export const Source = GObject.registerClass({
     _onNotificationDestroy(notification) {
         let index = this.notifications.indexOf(notification);
         if (index < 0)
-            return;
+            throw new Error('Notification was already removed previously');
 
         this.notifications.splice(index, 1);
         this.emit('notification-removed', notification);
         this.countUpdated();
 
-        if (this.notifications.length === 0)
+        if (!this._inDestruction && this.notifications.length === 0)
             this.destroy();
     }
 
@@ -555,8 +555,10 @@ export const Source = GObject.registerClass({
         if (this.notifications.includes(notification))
             return;
 
-        while (this.notifications.length >= MAX_NOTIFICATIONS_PER_SOURCE)
-            this.notifications.shift().destroy(NotificationDestroyedReason.EXPIRED);
+        while (this.notifications.length >= MAX_NOTIFICATIONS_PER_SOURCE) {
+            const [oldest] = this.notifications;
+            oldest.destroy(NotificationDestroyedReason.EXPIRED);
+        }
 
         notification.connect('destroy', this._onNotificationDestroy.bind(this));
         notification.connect('notify::acknowledged', () => {
@@ -573,11 +575,12 @@ export const Source = GObject.registerClass({
     }
 
     destroy(reason) {
-        let notifications = this.notifications;
-        this.notifications = [];
+        this._inDestruction = true;
 
-        for (let i = 0; i < notifications.length; i++)
-            notifications[i].destroy(reason);
+        while (this.notifications.length > 0) {
+            const [oldest] = this.notifications;
+            oldest.destroy(reason);
+        }
 
         this.emit('destroy', reason);